﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using UCOLOR.Helpers;
using UCOLOR.Model;
using UColor.WPF;
using UColor.Modules;
using UCOLOR.App.Extend;

namespace UCOLOR.View
{
    /// <summary>
    /// HomeView.xaml 的交互逻辑
    /// </summary>
    public partial class ProductListViewDemo : UCModule 
    {
        public ProductListViewDemo()
        {
            InitializeComponent();
        }

        public int ViewType = 1;
        public ProductListViewDemo(string product_no)
        {
            InitializeComponent();
            ShowPartDataView(product_no);
        }
       

        public IList<Product> data
        {
            get;
            set;
        }

        public IList<SalesPart> salesPartData
        {
            get;
            set;
        }

        public void ShowPartDataView(IList<SalesPart> list)
        {
            this.DirList.ItemsSource = list;
        }
        public System.Collections.IEnumerable PhoteSources
        {
            get
            {
                return this.DirList.ItemsSource;
            }
            set
            {
                this.DirList.ItemsSource = value;
            }

        }

        public void ShowPartDataView(string product_no)
        {
            IList<SalesPart> list ;
            if(ViewType == 1)
                //this.DirList.ItemsSource list
            list= DataHelper.getSalesPart("", product_no);
            else
                //this.DirList.ItemsSource =
                list= DataHelper.getSalesPart( product_no,"");

            foreach (SalesPart part in list)
            {
                TileEx tile = new TileEx();
                tile.Content = part;
                // = part.PhotoSource;
                if (part.ImageZoomWidth > 200)
                {
                    tile.Style = Resources["HorizontalTile"] as Style;
                }
                else
                {
                    tile.Style = Resources["VerticalTile"] as Style;
                }
                //tile.Template
                tile.Width = part.ImageZoomWidth;
                tile.Height = part.ImageZoomHeight;
                tile.Click += new EventHandler(Tile_Click);
                this.DirList.Children.Add(tile);
            }
            //view.DirList.Children.Add("") = data;

        }

        public void ShowView()
        {
            ProductView view = new ProductView(1);
            

        }

        public void ShowView(int id)
        {
           // ProductView view = new ProductView(id);
           // view.DirList.ItemsSource = data;
        }

        private void Tile_Click(object sender, EventArgs e)
        {
            string catalog_no = "";
            if (((DevExpress.Xpf.LayoutControl.Tile)sender).Content is SalesPart)
            {
                catalog_no = ((UCOLOR.Model.SalesPart)(((DevExpress.Xpf.LayoutControl.Tile)sender).Content)).catalog_no;

                ProductView view = new ProductView(catalog_no);
                view.ParentModulePage = this.ParentModulePage;
                this.ParentModulePage.OpenModule(view);
                view.ShowProduct(1);
            }
            else if(((DevExpress.Xpf.LayoutControl.Tile)sender).Content is PartProductCode)
            {
                catalog_no = ((PartProductCode)(((DevExpress.Xpf.LayoutControl.Tile)sender).Content)).product_code;
                HomeView dir = new HomeView(2, catalog_no, this.ParentModulePage);
              
                this.ParentModulePage.OpenModule(dir);
            }
        }

        private void Tile_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            string catalog_no = "";
            if (((DevExpress.Xpf.LayoutControl.Tile)sender).Content is PartProductFamily)
            {
                catalog_no = ((UCOLOR.Model.PartProductFamily)(((DevExpress.Xpf.LayoutControl.Tile)sender).Content)).product_family;

                GalleryPhotoViewer view = new GalleryPhotoViewer("",catalog_no,2);
                this.ParentModulePage.OpenModule(view);
                
            }
            else if (((DevExpress.Xpf.LayoutControl.Tile)sender).Content is PartProductCode)
            {
                catalog_no = ((PartProductCode)(((DevExpress.Xpf.LayoutControl.Tile)sender).Content)).product_code;
                GalleryPhotoViewer view = new GalleryPhotoViewer(catalog_no, "", 1);
                this.ParentModulePage.OpenModule(view);
            }
        }
    }
}
